package org.dromara.shopping.controller;

import java.util.Arrays;
import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.common.mybatis.core.page.PageUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.shopping.domain.TitleMenuSectionLinks;
import org.dromara.shopping.service.ITitleMenuSectionLinksService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 每个内容行里的数据
 *
 * @author Mr.Zhou
 * @date 2025-01-17
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/shopping/menuSectionLinks")
public class TitleMenuSectionLinksController extends BaseController {

    private final ITitleMenuSectionLinksService titleMenuSectionLinksService;

    /**
     * 查询每个内容行里的数据列表
     */
    @SaCheckPermission("shopping:menuSectionLinks:list")
    @GetMapping("/list")
    public TableDataInfo<TitleMenuSectionLinks> list(TitleMenuSectionLinks titleMenuSectionLinks, PageQuery pageQuery) {
        QueryWrapper<TitleMenuSectionLinks> qw = new QueryWrapper<>();

        TableDataInfo<TitleMenuSectionLinks> td = PageUtils.buildDataInfo(titleMenuSectionLinksService.page(PageUtils.buildPage(),qw));
        List<TitleMenuSectionLinks> list = td.getRows();
        return td;
    }

    /**
     * 导出每个内容行里的数据列表
     */
    @SaCheckPermission("shopping:menuSectionLinks:export")
    @Log(title = "每个内容行里的数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TitleMenuSectionLinks titleMenuSectionLinks, HttpServletResponse response) {
        List<TitleMenuSectionLinks> list = titleMenuSectionLinksService.list();
        ExcelUtil.exportExcel(list, "每个内容行里的数据", TitleMenuSectionLinks.class, response);
    }

    /**
     * 获取每个内容行里的数据详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("shopping:menuSectionLinks:query")
    @GetMapping("/{id}")
    public R<TitleMenuSectionLinks> getInfo(@NotNull(message = "主键不能为空") @PathVariable Integer id) {
        return R.ok(titleMenuSectionLinksService.getById(id));
    }

    /**
     * 新增每个内容行里的数据
     */
    @SaCheckPermission("shopping:menuSectionLinks:add")
    @Log(title = "每个内容行里的数据", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TitleMenuSectionLinks titleMenuSectionLinks) {
        return toAjax(titleMenuSectionLinksService.save(titleMenuSectionLinks));
    }

    /**
     * 修改每个内容行里的数据
     */
    @SaCheckPermission("shopping:menuSectionLinks:edit")
    @Log(title = "每个内容行里的数据", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TitleMenuSectionLinks titleMenuSectionLinks) {
        return toAjax(titleMenuSectionLinksService.updateById(titleMenuSectionLinks));
    }

    /**
     * 删除每个内容行里的数据
     *
     * @param ids 主键串
     */
    @SaCheckPermission("shopping:menuSectionLinks:remove")
    @Log(title = "每个内容行里的数据", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")  @PathVariable Integer[] ids) {
        return toAjax(titleMenuSectionLinksService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
